package cn.itcast.user.servicer.servicerimpe;

import cn.itcast.hmall.dto.common.ThreadLocalUtil;
import cn.itcast.hmall.pojo.user.Address;
import cn.itcast.hmall.pojo.user.User;
import cn.itcast.user.Mapper.AddressMapper;
import cn.itcast.user.Mapper.UserMapper;
import cn.itcast.user.servicer.servicerUser;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ServicerUserimpe  implements servicerUser {
    @Autowired
    AddressMapper ressMapper;
    @Autowired
    UserMapper userMapper;
    @Override
    public List<Address> idServiceS() {
        Long adderss = ThreadLocalUtil.getUserId();
        //条件添加
        LambdaQueryWrapper<Address> objectLambdaQueryWrapper = Wrappers.lambdaQuery();
        objectLambdaQueryWrapper.eq(Address::getUserId, adderss);
        List<Address> addresses = ressMapper.selectList(objectLambdaQueryWrapper);
        return addresses;
    }

    @Override
    public Address idService(String id) {
        long l = Long.parseLong(id);
        Address address = ressMapper.selectById(id);
        return address;
    }

    @Override
    public User getById(Long id) {
        User user = userMapper.selectById(id);
        return user;
    }

    @Override
    public int updateById(User user) {
        int i = userMapper.updateById(user);
        return i;
    }

}
